﻿namespace WindowsServiceSample
{
    using System.Configuration;

    using Preflight;
    using Preflight.Fluent;
    using Preflight.Verifications;

    public static class ApplicationVerificationFactoryBuilder
    {
        public static IVerificationFactory CreateFactory()
        {
            return 
            Define.Application()
                .Named("Sample Web Service")
                .OfCategory("Samples")
                .OfVersion("1.0.0.0")
                .Requires(GetDatabaseVerification())
                .Requires(GetOutboundConnectivityVerification());
        }

        private static IVerification GetDatabaseVerification()
        {
            var sqlVerificationDescription = new SqlConnectionVerificationDescription
                {
                    Category = StandardCategoryNames.CriticalResource,
                    GetConnectionString = () => ConfigurationManager.AppSettings["ConnectionString"],
                    VerificationName = "Primary Database"
                };

            return VerificationBuilder.Instance.BuildVerification(sqlVerificationDescription);
        }

        private static IVerification GetOutboundConnectivityVerification()
        {
            var webGetVerification = new WebGetVerificationDescription
                {
                    Category = StandardCategoryNames.CriticalResource,
                    GetUrl = () => "http://www.bing.com",
                    VerificationName = "Outbound Connectivity"
                };

            return VerificationBuilder.Instance.BuildVerification(webGetVerification);
        }
    }
}
